<?php

namespace App\Admin\Http\Requests;

class CodeRequest extends Request
{
    /**
     * 用户请求认证
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 设置请求验证规则
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'name' => 'required|max:50',
            'parent_code' => 'max:50',
            'description' => 'max:100',
            'sort' => 'required|integer|min:0',
            'tree' => 'required|boolean',
        ];

        if ($this->route('codes') != $this->input('code')) {
            $rules['code'] = 'required|max:50|unique:codes';
        }

        return $rules;
    }

    /**
     * 翻译验证属性
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'code' => '代码',
            'name' => '名称',
            'type_id' => '代码类别',
            'description' => '描述',
            'sort' => '排序',
            'tree' => '叶子节点',
        ];
    }
}
